package cn.bdqn.web;

import cn.bdqn.entity.Users;
import cn.bdqn.service.Imp.UsersserviceImp;
import cn.bdqn.service.Usersservice;
import cn.bdqn.utils.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 梁非凡
 * @date 2018/8/15 16:08
 */
@WebServlet("/CvipServlet")
public class CvipServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String currentPageStr = request.getParameter("currentPage");
        String pageSizeStr = request.getParameter("pageSize");
        String name = request.getParameter("name");
        Integer currentPage=1;
        if (currentPageStr!=null&&currentPageStr!=""){
            currentPage = Integer.parseInt(currentPageStr);
        }
        Integer pageSize=5;
        if (pageSizeStr!=null&&pageSizeStr!=""){
            pageSize= Integer.parseInt(pageSizeStr);
        }
        Usersservice usersservice=new UsersserviceImp();
        PageBean<Users> pageBean = usersservice.findpageByname(name, currentPage, pageSize);
        if (pageBean.getTotalCount()!=0){
            request.setAttribute("pageBean",pageBean);
        request.getRequestDispatcher(request.getContextPath() + "/management.jsp").forward(request, response);

        }else {
            request.setAttribute("error","抱歉，暂无数据");
            request.getRequestDispatcher(request.getContextPath() + "/management.jsp").forward(request, response);
        }
    }
}
